﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace JBeamLibrary.Tools
{
    public static class StringExtension
    {
        public static string LastDelimitedPart(this string str, string delimiter, bool includeDelimiter = false)
        {
            if (string.IsNullOrEmpty(str) || !str.Contains(delimiter)) return str;

            var startIndex = str.LastIndexOf(delimiter, StringComparison.Ordinal);

            return includeDelimiter ? str.Substring(startIndex) : str.Substring(startIndex + 1);
        }

        public static string Capitalize(this string str)
        {
            if (string.IsNullOrEmpty(str)) return str;

            return
                str.Length == 1
                ? str.ToUpperInvariant()
                : str.Substring(0, 1).ToUpperInvariant() + str.Substring(1);
        }

        public static string Propertize(this string str)
        {
            if (string.IsNullOrEmpty(str)) return str;

            return
                str.Length == 1
                ? str.ToLowerInvariant()
                : str.Substring(0, 1).ToLowerInvariant() + str.Substring(1);
        }
    }
}
